草庐IT

dart - Flutter Future 和 setstate

全部标签

flutter - Dart - 强制一个类有一个工厂

我有以下模型:作者发布classAuthorimplementsModel{Stringname;Stringemail;User({this.name,this.email});factoryUser.fromMap(Mapdata){returnUser(name:data['name']??'JonDoe'email:data['email']??'jon@doe.com';)}}classPostimplementsModel{Userauthor;Stringcontent;User({this.name,this.email});factoryPost.fromMap(Ma

flutter - setState 函数不更新有状态小部件下的图像

我正在尝试构建骰子游戏,如果用户单击该游戏,应该从Assets文件夹更改图像,但图像没有改变,但终端中的值正在更新setState方法可能无法正常工作import'package:flutter/material.dart';import'dart:math';voidmain(){returnrunApp(MaterialApp(home:Scaffold(backgroundColor:Colors.red,appBar:AppBar(title:Center(child:Text('Dicee')),backgroundColor:Colors.red,),body:DicePa

flutter - setState 函数不更新有状态小部件下的图像

我正在尝试构建骰子游戏,如果用户单击该游戏,应该从Assets文件夹更改图像,但图像没有改变,但终端中的值正在更新setState方法可能无法正常工作import'package:flutter/material.dart';import'dart:math';voidmain(){returnrunApp(MaterialApp(home:Scaffold(backgroundColor:Colors.red,appBar:AppBar(title:Center(child:Text('Dicee')),backgroundColor:Colors.red,),body:DicePa

flutter - Dart 语法杀了我 -> VoidCallback

我使用了一些代码,无法理解这种语法哲学:示例:SomeClasssomeClass=newSomeClass();classSomeClass{VoidCallback_callback;setonCallback(VoidCallbackcallback){_callback=callback;}someFunction(){if(_callback!=null){_callback();}}}...某处...在StatefulWidget类中:@overridevoidinitState(){super.initState();someClass.onCallback=_onCal

flutter - Dart 语法杀了我 -> VoidCallback

我使用了一些代码,无法理解这种语法哲学:示例:SomeClasssomeClass=newSomeClass();classSomeClass{VoidCallback_callback;setonCallback(VoidCallbackcallback){_callback=callback;}someFunction(){if(_callback!=null){_callback();}}}...某处...在StatefulWidget类中:@overridevoidinitState(){super.initState();someClass.onCallback=_onCal

flutter - BottomNavigatonBar 的 onTap(index) 方法上的 SetState() 不会重建小部件树

我正在尝试将webview_flutterWebView连接到BottomNavigationBar。我希望在点击选项卡时使用新URL重新加载View。在onTap回调我将_currentUrl更新为新的url并使用新的选项卡索引调用设置状态。为什么标签栏正在更新但网页View没有重建?我错过了什么?classWebViewAppextendsStatefulWidget{@overrideStatecreateState(){returnWebViewState();}}classWebViewStateextendsState{int_currentTabIndex=0;Strin

flutter - BottomNavigatonBar 的 onTap(index) 方法上的 SetState() 不会重建小部件树

我正在尝试将webview_flutterWebView连接到BottomNavigationBar。我希望在点击选项卡时使用新URL重新加载View。在onTap回调我将_currentUrl更新为新的url并使用新的选项卡索引调用设置状态。为什么标签栏正在更新但网页View没有重建?我错过了什么?classWebViewAppextendsStatefulWidget{@overrideStatecreateState(){returnWebViewState();}}classWebViewStateextendsState{int_currentTabIndex=0;Strin

flutter - 使用 Flutter 和 Dart,我怎样才能让这个 Future 工作?

我知道还有其他方法可以实现此目的,但我想通过initState()使用Future来使用SharedPreferences获取列表。下面说明了我想要实现的目标,但它没有按要求工作,因为Future在完成任务之前立即返回。这应该如何构建?import'package:flutter/material.dart';import'package:shared_preferences/shared_preferences.dart';class_MyHomePageStateextendsState{SharedPreferences_prefs;String_sMessage="Noresp

flutter - 使用 Flutter 和 Dart,我怎样才能让这个 Future 工作?

我知道还有其他方法可以实现此目的,但我想通过initState()使用Future来使用SharedPreferences获取列表。下面说明了我想要实现的目标,但它没有按要求工作,因为Future在完成任务之前立即返回。这应该如何构建?import'package:flutter/material.dart';import'package:shared_preferences/shared_preferences.dart';class_MyHomePageStateextendsState{SharedPreferences_prefs;String_sMessage="Noresp

class - 在 dart 中将 final 变量设为私有(private)是多余的吗?

下面的类有多个参数,但只有一些需要是final;我的问题是,我是否也应该将这些最终变量设为私有(private),或者这样做是否多余?classCar{finaldouble_galInFullTank;getgalInFullTank=>_galInFullTank;double_miDrivenToEmpty;getmiDrivenToEmpty=>_miDrivenToEmpty;double_mpg;getmpg=>_mpg;voidupdate(doublenewMiDrivenToEmpty){_miDrivenToEmpty=newMiDrivenToEmpty;_mpg